#!/bin/bash
# set -x
OPENTSDB_METRIC_PREFIX="goldwind"
OPENTSDB_METRIC="host.health"
test ! -z $OPENTSDB_METRIC_PREFIX && OPENTSDB_METRIC=$OPENTSDB_METRIC_PREFIX.$OPENTSDB_METRIC

while [[ true ]]; do
	cat host_list | while read line; do
		ip=$(echo $line | awk '{print $1}')
		host=$(echo $line | awk '{print $2}')
		if [[ ! -z $ip && ! -z $host ]]; then
			nc -z -w 5 $ip 22
			test $? -eq 0 && health=1 || health=0
			echo "put $OPENTSDB_METRIC $(date +%s) $health host=$host ip=$ip"
		fi
 	done 
#<<EOM
# 10.1.10.7 xudi
# 10.235.1.4 kmx-4
# EOM
	sleep 10
done

